<template>
  <div class="box-container accessModel flex-row row-between">
    <div class="left-tree">
      <!-- <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree> -->
      <Treeselect @treeSelect="treeSelect" :data="pp" />
    </div>
    <div class="right-box" v-loading="loading">
      <div class="top-step flex-row row-center column-center">
        <Card :cardObj="stepList[0]" :isActive="step >= 0" />
        <img class="trangleimg" src="@/assets/myself_img/icon_trangle.png" />
        <Card :cardObj="stepList[1]" :isActive="step > 0" />
        <img class="trangleimg" src="@/assets/myself_img/icon_trangle.png" />
        <Card :cardObj="stepList[2]" :isActive="step == 2" />
      </div>
      <div class="step-content" v-show="step == 0">
        <div class="btn-box flex-row column-center">
          <el-button
            icon="el-icon-upload"
            type="primary"
            size="small"
            @click="showDialog(0)"
            >指标体系导入</el-button
          >
          <el-button
            icon="el-icon-upload"
            type="primary"
            size="small"
            @click="showDialog(1)"
            >评估模型导入</el-button
          >
          <el-button
            icon="el-icon-upload"
            type="primary"
            size="small"
            @click="showDialog(2)"
            >暂存模型导入</el-button
          >
        </div>
        <div class="tab-btn flex-row row-center column-center">
          <div :class="btn == 0 ? 'active' : ''" @click="btnClick(0)">
            专家赋值
          </div>
          <div :class="btn == 1 ? 'active' : ''" @click="btnClick(1)">AHP</div>
        </div>
        <div class="box-content" v-show="btn == 0">
          <Title :obj="titleList[0]" />
          <!-- 专家赋值 指标体系赋值 overview2-->
          <div class="expertAssignment" id="changeTree0" v-if="!branch"></div>
          <g6-container
            class="expertAssignment"
            treeId="expertAssignment1"
            :treedata="branch"
            :operate="true"
            :modelDis ='true'
            @deleteTree="deleteTree"
            @updateTree="updateG6Tree"
            @addTree="addG6Tree"
            v-if="branch && btn == 0"
          >
          </g6-container>
          <Title :obj="titleList[1]" />
          <!-- 专家赋值 指标总览 overview-->
          <div class="indexView1" id="mountNode1" v-if="!indexTree"></div>
          <g6-container class="indexView1" treeId="indexView11" :treedata="indexTree" v-else></g6-container>
        </div>
        <div class="box-content" v-show="btn == 1">
          <Title :obj="titleList[4]" />
          <!-- AHP 指标体系总览 overview1-->
          <div class="indexView" id="changeTree1">
            <g6-container  :modelDis ='true' treeId="changeTree11" :treedata="branch"  v-if="branch && btn == 1"></g6-container>
          </div>
          <Title :obj="titleList[2]" />
          <div class="judgment flex-row row-wrap">
            <div class="btn flex-row" @click="getWeightList">
              <Card
                :cardObj="item"
                v-for="(item, i) in judgmentList"
                :key="i"
              />
            </div>
            <div class="box1">
              <row-line
                :key="rowLine"
                :labelList="labelList"
                :dataList="dataList"
                @handleCheck="checkBlock"
              />
            </div>
            <div class="box2">
              <Capacity @handleScore="getScore" />
            </div>
            <div class="box3">
              <progress-weight :num="calculate" :data="weightList" />
            </div>
          </div>
        </div>
      </div>
      <div
        class="step-content flex-row row-center column-center"
        v-show="step == 1"
      >
        <div class="step22">
          <Title :obj="titleList[3]" />
          <div class="step22-content">
            <div class="label">请选择算法模板</div>
            <div class="check-box">
              <el-radio v-model="radio" label="层次分析法" />
            </div>
            <div class="check-box">
              <el-radio v-model="radio" label="模糊评价法" />
            </div>
          </div>
        </div>
      </div>
      <div class="step-content box-container" v-show="step == 2">
        <table-com
        v-loading="step3Loading"
          style="height: calc(100% - 40px)"
          :isIndex="true"
          :dataSource="tableData"
          :columns="columns"
        >
          <template slot="normalizationAlg" slot-scope="scope">
            {{ getComputeName(scope.row.normalizationAlg) }}
          </template>
          <template slot="options" slot-scope="scope">
            <div class="my-btn-box flex-row row-center column-top">
              <span @click="optionFun(scope.row)">编辑</span>
            </div>
          </template>
        </table-com>
        <!-- <el-pagination

          background
          layout="total, prev, pager, next"
          :total="7"
          :current-page="1"
          style="text-align: right"
        /> -->
        <!-- @current-change="changeModelPage" -->
      </div>
      <div class="footer">
        <el-button
          icon="el-icon-check"
          type="primary"
          size="small"
          @click="temSave"
          v-show="step == 0"
          :disabled="!this.indexTree"
          >暂存</el-button
        >
        <el-button
          type="primary"
          size="small"
          @click="stepChange(-1)"
          v-show="step > 0"
          >上一步</el-button
        >
        <el-button
          :disabled="!this.indexTree"
          type="primary"
          size="small"
          @click="stepChange(1)"
          v-show="step < 2"
          >下一步</el-button
        >
        <el-button
          type="primary"
          size="small"
          @click="submit"
          v-show="step == 2"
          >发布</el-button
        >
      </div>
      <el-dialog
        :title="dialogTitle"
        :visible.sync="dialogVisible"
        :before-close="handleClose"
      >
        <div class="compute-title" v-show="dialogTitle == '算法选择'">
          <span class="name">指标名称</span>
          <span class="indexName">{{ checkRow ? checkRow.name : "" }}</span>
        </div>
        <el-form
          v-show="dialogTitle != '算法选择'"
          :inline="true"
          size="mini"
          :model="modelForm"
          class="demo-form-inline"
          style="display: flex; justify-content: space-between"
        >
          <el-form-item label="创建时间">
            <el-date-picker
              style="width: 200px"
              v-model="modelForm.createTime"
              type="daterange"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="类型">
            <el-select v-model="modelForm.type" placeholder="类型" clearable>
              <el-option label="模糊" value="模糊"></el-option>
              <el-option label="AHP" value="AHP"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="模型名称">
            <el-input
              v-model="modelForm.name"
              placeholder="模型名称"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item>
            <!-- <el-button type="primary" @click="modelSearch(dialogTitle, 1)"> -->
            <el-button type="primary" @click="changeModelPage(1)">
              <img :src="require('../../../assets/images/cha3.png')" alt="" srcset="" />
              查询
            </el-button>
          </el-form-item>
        </el-form>
        <table-com
          style="height: 500px"
          v-show="dialogTitle == '算法选择'"
          ref="standardTable"
          :isSelect="true"
          :isIndex="true"
          @selectFun="handleSelection"
          :dataSource="computedData"
          :columns="computedColumns"
        />
        <table-com
          style="height: 500px"
          v-loading="modelLoading"
          v-show="dialogTitle != '算法选择'"
          ref="importTable"
          :isSelect="true"
          :isIndex="true"
          @selectFun="handleSelection"
          :dataSource="modelList"
          :columns="modelColumns"
        >
          <template slot="options" slot-scope="scope" v-show='dialogTitle == "暂存模型列表"'>
            <div>
              <el-button
                size="mini"
                type="danger"
                @click="deleteById(scope.row)">删除</el-button>
            </div>
          </template>
        </table-com>
        <el-pagination
          v-show="dialogTitle != '算法选择'"
          background
          layout="total, prev, pager, next"
          :total="modelTotal"
          :current-page="modelCurrent"
          @current-change="changeModelPage"
          style="
            text-align: right;
            padding: 15px 0;
            border-bottom: 1px solid #c3d5e3;
          "
        />
        <!-- @current-change="changeModelPage" -->
        <template #footer>
          <el-button type="primary" @click="getComputed">确定</el-button>
          <el-button @click="handleClose">取消</el-button>
        </template>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import Card from "@/components/myselfCom/stepCard.vue";
import Title from "@/components/myselfCom/boxTitle.vue";
import RowLine from "./rowLine.vue";
import Capacity from "./capacity.vue";
import ProgressWeight from "./progress.vue";
import TableCom from "@/components/myselfCom/tableCom.vue";
import Treeselect from "@/components/myselfCom/systemTree";
import { ppc } from "./tree.js";
import { eisIndicatorSystem, getModelByStatus, selectModelTreeById, queryModelById, selectModelTreeByIdNew, saveModelNode, checkModelNode,
  labCalc, getModelNodeList, computedlist, indicatorSet,deleteById } from '@/api/accessModel.js'
import {listData } from '@/api/system/dict/data.js'
import G6Container from "@/components/G6Container/index";
export default {
  name: "",
  components: {
    Card,
    Title,
    RowLine,
    Capacity,
    ProgressWeight,
    TableCom,
    Treeselect,
    G6Container
  },
  props: {
    // data: {
    //   type: Array,
    //   default: () => [],
    // },
  },
  data() {
    return {
      pp: null, //树图静态数据
      loading: false, // 中间区域loading
      //  步骤
      step: 0,
      stepList: [
        {
          imgActive: require("@/assets/myself_img/icon_hammer.png"),
          imgNormal: require("@/assets/myself_img/icon_hammer_n.png"),
          text: "指标权重设置",
        },
        {
          imgActive: require("@/assets/myself_img/icon_squire.png"),
          imgNormal: require("@/assets/myself_img/icon_squire_n.png"),
          text: "指标聚合设置",
        },
        {
          imgActive: require("@/assets/myself_img/icon_computed.png"),
          imgNormal: require("@/assets/myself_img/icon_computed_n.png"),
          text: "指标解算设置",
        },
      ],

      // 第一步指标权重设置
      btn: 0, //AHP1/专家赋值0
      titleList: [
        {
          img: require("@/assets/myself_img/icon_computed.png"),
          title: "指标体系赋值",
        },
        {
          img: require("@/assets/myself_img/icon_view.png"),
          title: "指标体系总览",
        },
        {
          img: require("@/assets/myself_img/icon_computed1.png"),
          title: "判断矩阵",
        },
        {
          img: require("@/assets/myself_img/icon_computed1.png"),
          title: "算法模版",
        },
        {
          img: require("@/assets/myself_img/icon_view.png"),
          title: "选中指标总览",
        },
        // { img: require('@/assets/myself_img/icon_editor.png'), title: '算法选择' },
      ],
      computedList: [
        {
          imgActive: "",
          imgNormal: "",
          text: "和",
        },
        {
          imgActive: "",
          imgNormal: "",
          text: "幂",
        },
        {
          imgActive: "",
          imgNormal: "",
          text: "根",
        },
      ],
      // 树形图
      g6Tree: {
        id: "1",
        num: "1.000",
        label: "WL系统能力",
        size: [120, 50],
        children: [
          {
            id: "2",
            num: "0.250",
            label: "WL系统能力",
            size: [120, 50],
            children: [
              { id: "5", num: "0.250", label: "WL系统能力", size: [40, 140] },
              { id: "6", num: "0.250", label: "WL系统能力", size: [40, 140] },
              { id: "7", num: "0.250", label: "WL系统能力", size: [40, 140] },
            ],
          },
          {
            id: "3",
            num: "0.250",
            label: "WL系统能力",
            size: [120, 50],
            children: [
              { id: "8", num: "0.250", label: "WL系统能力", size: [40, 140] },
              { id: "9", num: "0.250", label: "WL系统能力", size: [40, 140] },
              { id: "10", num: "0.250", label: "WL系统能力", size: [40, 140] },
            ],
          },
          {
            id: "4",
            num: "0.250",
            label: "WL系统能力",
            size: [120, 50],
            children: [
              { id: "11", num: "0.250", label: "WL系统能力", size: [40, 140] },
              { id: "12", num: "0.250", label: "WL系统能力", size: [40, 140] },
              { id: "13", num: "0.250", label: "WL系统能力", size: [40, 140] },
            ],
          },
        ],
      },
      judgmentList: [
        {
          imgNormal: require("@/assets/myself_img/icon_editor1.png"),
          text: "数据集导入",
        },
        {
          imgNormal: require("@/assets/myself_img/icon_check.png"),
          text: "一致性检验",
        },
      ],
      block: "", //选中块
      labelList: [], //表头
      dataList: [], //数据
      rowLine: false, // 列表渲染key
      calculate: "", //一致性比例
      weightList: [], //计算权重列表

      // 第二部指标聚合设置
      radio: "模糊评价法",

      // 第三部指标结算设置
      step3Loading: true,
      tableData: [
        { name: "JR种类", normalizationAlg: "分层乘积归一化" },
        { name: "JR数量", normalizationAlg: "是否归一化" },
        { name: "JR时间", normalizationAlg: "最小值线性归一化" },
        { name: "WL吞吐量", normalizationAlg: "线性归一化" },
        { name: "关键SB吞吐量", normalizationAlg: "最大值线性归一化" },
        { name: "WL重负荷下可用性", normalizationAlg: "三等级归一化（高、中、低）" },
        { name: "WLCS丢包率", normalizationAlg: "四等级归一化（高、中、低)" },
      ],
      columns: [
        { prop: "name", label: "分类名称" },
        { prop: "normalizationAlg", label: "数据归一化方法分类", isSlot: true },
        { prop: "options", label: "操作", isSlot: true, width: 80 },
      ],

      //被编辑row
      checkRow: null,

      // 模型导入/算法选择，弹窗
      dialogTitle: "",
      dialogVisible: false,

      // 算法选择列表
      computedData: [
        {
          key: "YCL_ZZSSF",
          label: "正整数算法",
        },
        {
          key: "YCL_JSPJZSF",
          label: "计算平均值算法_wait",
        },
        {
          key: "YCL_ZSSSF",
          label: "正实数算法",
        },
        {
          key: "YCL_PDSiDJSF",
          label: "判断四等级算法",
        },
        {
          key: "YCL_PDSDJSF",
          label: "判断三等级算法",
        },
        {
          key: "YCL_PDSFSF",
          label: "判断是否算法",
        },
        {
          key: "YCL_FFSSSF",
          label: "非负实数算法",
        },
        {
          key: "YCL_FFZSSF",
          label: "非负整数算法",
        },
      ],
      // [
      //   { sort: "分层乘积归一化" },
      //   { sort: "是否归一化" },
      //   { sort: "最小值线性归一化" },
      //   { sort: "线性归一化" },
      //   { sort: "最大值线性归一化" },
      //   { sort: "三等级归一化（高、中、低" },
      //   { sort: "四等级归一化（高、中、低)" },
      // ],
      computedColumns: [{ prop: "label", label: "数据归一化方法分类" }],
      computedObj: {},

      // 模型导入列表
      modelForm: {
        name: '',
        type: '',
        createTime:[],
      },
      modelTotal:0,
      modelCurrent:1,
      modelLoading: false,
      modelList: [],
      modelColumns: [
        { prop: "name", label: "名称" },
        { prop: "type", label: "类型" },
        { prop: "createTime", label: "创建时间" },
        { prop: "createBy", label: "创建人员" },
        { prop: "polymerizationAlg", label: "算法类型" },
        { prop: 'options', label: "操作", isSlot: true,width:80 },
      ],
      modelImport: null,
      overView: null, //专家赋值指标总览
      overView0: null, //专家赋值指标体系赋值
      overView1: null, //AHP选中指标总览
      branch: null,//{ label: 'pppp', id: 'p', size: [120, 50], num: '0'}//null,
    };
  },
  computed: {
    indexTree: function (){
      if(this.pp && this.pp.length>0){
        return this.pp[0];
      }else{
        return null;
      }
    }
  },
  mounted() {
    this.computeSelectList()
    const id = this.$route.query.id;
    if(id){
      this.getTreeData(id)
    }
    // this.formatTree(ppc);
    // this.pp = [data];
  },
  methods: {
    deleteById(row){
      this.$modal.confirm('是否确认删除名称为"' + row.name + '"的模型？').then(function() {
        return deleteById({id:row.id})
      }).then(() => {
        this.getModelList(1,1)
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});


      // this.$modal.confirm('是否确认删除名称为"' + row.name + '"的模型？').then(function() {
      //   return deleteById({id:row.id}).then((res)=>{
      //     if(res.code == 200){
      //       this.$modal.msgSuccess("删除成功");
      //       this.getModelList(1,1)
      //
      //     }
      //
      //   });
      // })
    },
    // 评估模型2 暂存模型1
    getModelList(n, page){
      const params1 = {
        status: n,
        name: this.modelForm.name,
        type: this.modelForm.type,
        startTime: this.modelForm.createTime[0],
        endTime: this.modelForm.createTime[1],
        pageNo: page,
        pageSize: 10,
      }
      // console.log(params1, this.modelCurrent, '评估模型2 暂存模型1');
      getModelByStatus(params1).then( res => {
        if(res.code == 200){
          // console.log(res, '弹窗数据获取');
          this.modelLoading = false;
          this.modelList = res.data.records;
          this.modelTotal = res.data.total
        }
      })
    },
    // 指标体系导入
    // 这个n没啥用纯粹占位符
    getModelList1(n, page){
      const params1 = {
        status: 2,
        name: this.modelForm.name,
        type: this.modelForm.type,
        startTime: this.modelForm.createTime[0],
        endTime: this.modelForm.createTime[1],
        pageNo: page,
        pageSize: 10,
      }
      // console.log(params1, this.modelCurrent, '指标体系导入列表查询');
      eisIndicatorSystem(params1).then( res => {
        if(res.code == 200){
          this.modelLoading = false;
          this.modelList = res.data.records;
          this.modelTotal = res.data.total
        }
      })
    },
    // 获取所有叶子结点
    getLeaves(id){
      const params = {
        pageNo:'1',
        pageSize: '9999',
        id: id
      }
      getModelNodeList(params).then(res => {
        if(res.code == 200){
          this.tableData = res.data.records;
          this.step3Loading = false;
        }
      })
    },
    modelSearch(n, page){
      this.modelLoading = true;
      switch(n){
        case '指标体系模型列表':
          this.getModelList1('', page)
          break;
        case '暂存模型列表':
          this.getModelList(1, page)
          break;
        case '评估模型列表':
          this.getModelList(2, page)
          break;
      }
    },
    changeModelPage(val){
      this.modelCurrent = val;
      const d = this.dialogTitle
      this.modelSearch(d, val)
    },
    // 获取树形数据 暂存模型获取树结构
    getTreeData(id){
      selectModelTreeById(id).then(res => {
        if(res.code == 200){
          if(!res.data){
            this.$message({
              type: "warning",
              message: '模型对应树结构为空！'
            })
            this.pp = null;
          }else{
            const data = res.data
            this.formatTree(data);
            this.pp = [data];
            // this.getLeaves(res.data.id)
          }
          this.resetPage();
        }
      })
    },
    // 评估模型获取树结构
    getTreeData2(id){
      selectModelTreeByIdNew(id).then(res => {
        if(res.code == 200){
          if(!res.data){
            this.$message({
              type: "warning",
              message: '模型对应树结构为空！'
            })
            this.pp = null;
          }else{
            const data = res.data
            this.formatTree(data);
            this.pp = [data];
            this.getLeaves(res.data.id)
          }
          this.resetPage();
        }
      })
    },
    // 指标体系获取树结构
    getTreeData1(id){
      queryModelById(id).then(res => {
        if(res.code == 200){
          if(!res.data){
            this.$message({
              type: "warning",
              message: '指标对应树结构为空！'
            })
            this.pp = null;
          }else{
            const data = res.data
            this.formatTree(data);
            this.pp = [data];
          }
          this.resetPage();
        }
      })
    },
    deleteChildren(e){
      let childs = e
      for (let i = childs.children.length; i--; i > 0) {
        if (childs.children[i].children) {
          if (childs.children[i].children.pid == e.id) {
            this.deleteChildren(childs.children[i].children)
          } else {
            delete childs.children[i].children
          }
        }
      }

      this.branch = childs
    },

    // 左侧树形结构点击
    treeSelect(e) {
      this.branch = e;
      this.btnClick(this.btn)
    },
    updateG6Tree(tree){
      // this.branch = JSON.parse(JSON.stringify( tree ));
      // this.dataBranchChange(tree.id, this.pp);
      this.bigTree(tree, this.pp, '')
    },
    addG6Tree(tree){
      // console.log(tree, 'add');
      // this.branch = JSON.parse(JSON.stringify( tree ));
      // this.dataBranchChange(tree.id, this.pp, 'add');
      this.bigTree(tree, this.pp, 'add')
    },
    deleteTree(tree){
      // console.log(tree, 'pppp');
      // this.branch = JSON.parse(JSON.stringify( tree ));
      // this.dataBranchChange(tree, this.pp, 'delete');
      this.bigTree(tree, this.pp, 'delete')
    },
    bigTree(tree, all, status){
      if(status == 'delete'){
        const aim = this.lookupSearch(tree.pid, all);
        const i = aim.children.findIndex(item => item.id == tree.id);
        if(i != -1){
          aim.children.splice(i, 1)
        }
      }else if(status == 'add'){
        const aim = this.lookupSearch(tree.pid, all);
        // tree.pid = aim.id;
        // console.log('新增子结点', tree, '父节点', aim);
        if(!aim.children){
          aim.children = []
        }
        aim.children.push(tree)
        this.branch = aim
      }else{//修改
        const aim = this.lookupSearch(tree.id, all)
        aim.num = tree.num;
        aim.label = tree.label;
        aim.num = tree.num;
        aim.size = tree.size;
        tree.children.forEach((branch,j) => {
          aim.children[j].num =tree.children[j].num
          aim.children[j].label = tree.children[j].label
          aim.children[j].size = tree.children[j].size
        })
        this.branch = aim

      }
    },
    lookupSearch(id, all){
      let result;
      for(var i=0; i<all.length; i++){
        let item = all[i];
        if( item.id && item.id == id){
          result = item
          return result;
        }else if(item.children && item.children.length>0){
          result = this.lookupSearch( id, item.children)
          if(result){
            return result;
          }
        }
      }
      return result;
    },
    // 图表改变返回给树结构
    dataBranchChange(id, all, status){
      for(var i=0; i<all.length; i++){
        let item = all[i];
        if( item.id && item.id == id){
          if(status == 'delete'){
            // console.log(item, this.branch, 'delete');
            item.children.forEach((branch,j) => {
              const tt = this.branch.children.findIndex(pp => pp.id == branch.id )
              if(tt == -1){
                item.children.splice(j, 1)
              }
            })
          }else if(status == 'add'){
            this.branch.children.forEach((branch,j) => {
              const tt = item.children.findIndex(pp => pp.id == branch.id )
              if(tt == -1){
                item.children.push(branch)
              }
            })
          }else{
            item.label = this.branch.label;
            item.num = this.branch.num;
            item.size = this.branch.size;
            item.children.forEach((branch,j) => {
              item.children[j].num = this.branch.children[j].num
              item.children[j].label = this.branch.children[j].label
              item.children[j].size = this.branch.children[j].size
            })

          }
          return
        }else if(item.children && item.children.length>0){
          this.dataBranchChange( id, item.children, status)
        }
      }
    },
    // 下一步/上一步
    stepChange(n) {
      if(this.step == 0){
        let total = 0
        if(this.branch){
          this.branch.children.forEach(item => {
            total = total + Number(item.num)*1000000
          })
          if(total/1000000 !==1){//点暂存或者下一步校验子节点
            return this.$message.warning('子结点权重需等于1！')
          }
        }

        checkModelNode(this.indexTree).then(() => {
          this.getLeaves(this.pp[0].id)
        })
        // .then(res => {
        //   if(res.code == 500){
        //     this.step++
        //   }else{
        //     this.$message({ type: "warning", message: '请先暂存树结构，再进行下一步操作！'})
        //   }
        // })
      }
      this.step += n;
      if(this.step == 2){
        this.step3Loading = true;
        this.getLeaves(this.pp[0].id)
        // console.log(this.step3Loading,'00-')
        // console.log(this.step, this.step3Loading, 'third');
        // if(this.step3Loading) this.step3Loading = false;
        // else this.step3Loading = true;
        // debugger;
      }
    },
    // AHP1/专家赋值0
    btnClick(n) {
      this.btn = n;
      if(!this.branch){
        return ;
      }
      if(n == 1){
        this.labelList = this.branch.children.map((item) => item.label);
        let data = [];
        for (var i = 0; i < this.labelList.length; i++) {
          data.push([]);
          for (var j = 0; j < this.labelList.length; j++) {
            if (i == j) {
              data[i][j] = "1";
            } else {
              data[i][j] = "";
            }
          }
          this.dataList = data;
          this.calculate = "";
          this.weightList = [];
        }
      }
    },
    // AHP判断矩阵选中
    checkBlock(val) {
      this.block = val;
    },
    // AHP判断矩阵打分
    getScore(val) {
      let val1 = "";
      if (val.indexOf("/") > -1) {
        const arr = val.split("/");
        val1 = arr[1];
      } else {
        val1 = "1/" + val;
      }
      if (this.block) {
        const v = this.block;
        this.dataList[v[0]][v[1]] = val;
        this.dataList[v[1]][v[0]] = val1;
        this.rowLine = !this.rowLine;
      }
    },
    // 一致性检验
    getWeightList(e) {
      if (e.target.innerText == "一致性检验") {
        const d = JSON.stringify(this.dataList).replace(/"/g, '')
        // const res = {
        //   "msg": "操作成功",
        //   "code": 200,
        //   "data": {
        //       "result_string": "[\"{\\\"res\\\":\\\"[0.7985961426166699, 0.0964864190485761, 0.10491743833475403]\\\",\\\"cr\\\":0.0067516972403216}\"]",
        //       "result_message": "[\"处理完成\"]"
        //   }
        // }
        labCalc({judgment_matrix: '"'+d+'"'}).then(res => {
          if(res.code == 200){
              // console.log(res, '一致性检验');
            const arr = res.data.result_string.replace(/"|\\|\[|{|:|[a-z]|\]|}/g,'').split(',')
            const arr2 = res.data.result_message.replace(/"|\\|\[|{|:|[a-z]|\]|}/g,'').split(',')

            if(res.data.result_message== "[\"处理完成\"]"){
              this.branch.children.forEach((item,i) => {
                item.num = Number(arr[i]).toFixed(5)
              })
              this.dataBranchChange(this.branch.id, this.pp);
              this.weightList = JSON.parse(JSON.stringify(this.branch.children))
              this.calculate = Number(arr.pop()).toFixed(5)
            }else{
              this.calculate = Number(arr2.join(' ').split('为').pop()).toFixed(5)
              this.$message.error(arr2)
            }
          }
        })
      }
    },
    // 算法选择
    optionFun(row) {
      this.checkRow = row;
      this.showDialog();
    },
    getComputeName(key){
      // console.log(key, this.computedData, '0000000');
      const obj = this.computedData.find(item => item.key == key)|| { label: '--'};
      return obj.label;
    },
    computeSelectList(){
      computedlist('').then(res => {
        if(res.code == 200){
          console.log(res, 'suanfa列表');
          this.computedData = res.data;
        }
      })
    },
    // 模型/算法选择
    handleSelection(val) {
      const ref =
        this.dialogTitle == "算法选择" ? "standardTable" : "importTable";
      let pp = null;
      if (val.length == 0) {
        return (pp = null);
      } else if (val.length == 1) {
        pp = val[0];
      } else {
        this.$refs[ref].$refs.standardTable.clearSelection();
        this.$refs[ref].$refs.standardTable.toggleRowSelection(val.pop(), true);
        pp = val.pop();
      }
      if (this.dialogTitle == "算法选择") {
        this.computedObj = pp;
        // console.log(this.computedObj, this.dialogTitle, 'selection');
      } else {
        this.modelImport = pp;
        // console.log(this.modelImport, this.dialogTitle, 'selection');
      }
    },
    // 模型/算法显示弹窗
    showDialog(n) {
      this.computedObj = null; // 清空算法选中值
      this.modelImport = null; // 清空模型导入选中值
      switch (n) {
        case 0:
          this.dialogTitle = "指标体系模型列表";
          this.getModelList1('', 1);
          break;
        case 1:
          this.dialogTitle = "评估模型列表";
          this.getModelList(2,1)
          break;
        case 2:
          this.dialogTitle = "暂存模型列表";
          this.getModelList(1,1)
          break;
        default:
          this.dialogTitle = "算法选择";
          break;
      }
      this.modelLoading = true;
      this.dialogVisible = true;
    },
    // 模型/算法弹窗关闭
    handleClose() {
      this.$refs.standardTable.$refs.standardTable.clearSelection(); // 清空选中效果
      this.$refs.importTable.$refs.standardTable.clearSelection();
      this.modelForm = {
        name: '',
        type: '',
        createTime:[],
      },
      this.modelCurrent = 1;
      this.dialogVisible = false; //弹窗消失
    },
    // 模型/算法选择点击确定
    getComputed() {
      this.handleClose();
      if (this.dialogTitle == "算法选择") {
        // console.log(this.computedObj, "算法选择");
        this.checkRow.normalizationAlg = this.computedObj.key; // 修改已选择算法模型
      } else if(this.dialogTitle == '指标体系模型列表'){
        this.getTreeData1(this.modelImport.id)
        this.btn=0
      }else if(this.dialogTitle == '暂存模型列表'){
        this.getTreeData(this.modelImport.id)
        this.btn=0

      }else{
        this.getTreeData2(this.modelImport.id)
        this.btn=0

      }
    },

    //  暂存
    temSave() {
      let total = 0
        if(this.branch){
          this.branch.children.forEach(item => {
            total = total + Number(item.num)*1000000
          })
          if(total/1000000 !==1){//点暂存或者下一步校验子节点
            return this.$message.warning('子结点权重需等于1！')
          }else{
            this.zancun()
          }
      }else{
       this.zancun()
      }
    },
    //暂存
    zancun(){
      console.log(this.indexTree,'000009')
      saveModelNode(this.indexTree).then(res => {
        if(res.code == 200){
          this.$message({
            type: 'success',
            message: '暂存成功'
          })
        }
      })
    },
    // 提交
    submit() {
      console.log("提交");
      const params = {
        id: this.indexTree.id,
        name: this.indexTree.name,
        polymerizationAlg: this.radio,
        nodeList: this.tableData,
      }
      indicatorSet(params).then(res => {
        if(res.code == 200){
          this.$message({
            type: 'success',
            message: '发布成功！'
          })
          this.resetPage()
          this.step = 0
        }
      })
    },
    // 生成几个随机数和为1
    getNumber(n) {
      let arr = [];
      let total = 0;
      let arr1 = [];
      for (var i = 0; i < n; i++) {
        const num = Math.floor(Math.random() * 100);
        arr.push(num);
        total += num;
      }
      for (var i = 0; i < n; i++) {
        arr1.push((arr[i] / total).toFixed(3));
      }
      return arr1;
    },
    addSize(tree) {
      tree.forEach((node) => {
        node.size = [120, 50];
        node.num = "0";
        if (node.children) {
          this.addSize(node.children);
        } else {
          node.size = [40, 140];
        }
      });
      return tree;
    },
    formatTree(node) {
      if (!node) {
        return;
      }
      node.size = [120, 50];
      // console.log(node);
      node.num = node.num? node.num.toString(): '0';
      if (node.children && node.children.length) {
        var i = 0;
        for (i = 0; i < node.children.length; i++) {
          this.formatTree(node.children[i]);
        }
      }
    },
    resetPage(){
      // if(!this.overView){
      //   this.overView = setG6Data("mountNode", this.pp[0]);
      // }else{
      //   resetGraphData1(this.pp[0], this.overView)
      // }
      // this.branch = null
      // if(this.overView0){
      //   this.overView0.clear();
      // }
      // if(this.overView1){
      //   this.overView1.clear();
      //   this.labelList = [];
      //   this.dataList = [];
      //   this.weightList = [];
      // }
      // this.pp = null
      this.branch = null;
      this.labelList = [];
      this.dataList = [];
      this.weightList = [];
      this.tableData = []
    },

  }
};
</script>
<style lang="scss" scoped>
.accessModel {
  height: calc(100vh - 84px);
  .left-tree,
  .top-step,
  .step-content {
    border-radius: 10px;
    background-color: #fff;
  }
  .left-tree {
    width: calc(18.5% - 10px);
    height: 100%;
    margin-right: 10px;
    padding: 15px 10px;
    box-sizing: border-box;
  }
  .right-box {
    width: 82%;
    height: 100%;
    // overflow: scroll; // tem------
  }
  .top-step {
    background-color: #fff;
    height: 70px;
    margin-bottom: 10px;
    .stepCard {
      width: 180px;
      height: 40px;
      margin: 0 30px;
    }
    .trangleimg {
      width: 20px;
      height: 20px;
    }
  }
  .btn-box {
    background-color: #fff;
    border-radius: 10px 10px 0 0;
    height: 50px;
    border-bottom: 1px solid #c3d5e3;
    padding: 0 2%;
  }
  .tab-btn {
    background-color: #fff;
    height: 60px;
    div {
      font-size: 18px;
      font-family: Alibaba PuHuiTi;
      font-weight: 500;
      color: #757980;
      display: inline-block;
      text-align: center;

      width: 100px;
      height: 30px;
      line-height: 30px;

      border: 1px solid rgba(145, 178, 204, 0.3);
      cursor: pointer;
    }
    .active {
      color: #3771f5;
      background-color: rgba(54, 112, 245, 0.1);
    }
  }
  .step-content {
    width: 100%;
    height: calc(100% - 80px - 60px);
    border-radius: 10px 10px 0 0;
    .box-content {
      height: calc(100% - 50px - 60px);
      padding: 0 22px;
      box-sizing: border-box;
    }
  }
  .indexView,
  .judgment,
  .expertAssignment,
  .indexView1 {
    border: 1px solid rgba(145, 178, 204, 0.3);
    border-radius: 10px;
    overflow: hidden;
  }
  .expertAssignment {
    height: calc(40% - 51px);
  }
  .indexView1 {
    height: calc(60% - 51px);
  }
  .indexView {
    height: calc(46% - 51px);
    // height: 250px; // tem-----
  }
  .judgment {
    height: calc(54% - 51px);
    // height: 290px; // tem-----
    padding: 0 10px;
    box-sizing: border-box;
    .btn {
      height: 30px;
      width: 100%;
      border: none;
    }
    .btn .stepCard {
      width: 140px;
      margin: 0 15px;
      background-color: #fff;
      cursor: pointer;
    }
    & > div {
      height: calc(100% - 30px);
      border: 1px solid rgba(54, 112, 245, 0.1);
    }
    .box1 {
      width: 57.5%;
      overflow: scroll;
    }

    .box2 {
      width: calc(17% - 20px);
      margin: 0 10px;
    }
    .box3 {
      width: 25.5%;
    }
  }
  .step22 {
    width: 50%;
    height: 60%;
    .step22-content {
      width: 100%;
      height: 100px;
      border: 1px solid rgba(145, 178, 204, 0.3);
      border-radius: 4px;
      text-align: center;
      line-height: 100px;
    }
    .step22-content > div {
      width: 140px;
      height: 32px;
      line-height: 32px;
      display: inline-block;
      margin: 0 10px;
      font-size: 14px;
      font-family: Alibaba PuHuiTi;
      font-weight: 400;
      color: #a3a5af;
    }
    .check-box {
      background: #edf0f2;
      border-radius: 4px;
      color: #4c4d4e;
      &.active {
        background: #e4ecff;
        border: 1px solid #3670f5;
      }
    }
  }
  .compute-title {
    height: 40px;
    // line-height: 60px;
    font-size: 16px;
    font-family: Alibaba PuHuiTi;
    .name,
    .indexName {
      padding: 0 10px 5px;
      display: inline-block;
      vertical-align: middle;
    }
    .name {
      font-weight: 400;
      color: #393b3c;
      border-right: 1px solid rgb(221, 221, 221, 0.4);
    }
    .indexName {
      font-weight: 500;
      color: #3670f5;
    }
  }
  .footer {
    height: 60px;
    background-color: #fff;
    border-radius: 0 0 10px 10px;
    text-align: center;
    line-height: 40px;
  }
}
</style>
<style lang="scss">
// 整个项目生效
.accessModel {
  .el-dialog {
    width: 1000px;
  }
}
</style>
